package com.xz.service.impl;

import com.xz.bean.Actress;
import com.xz.bean.Arzon;
import com.xz.dao.ArzonDao;
import com.xz.service.ArzonService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by YLZX-Z0107 on 2014/7/18.
 */
public class ArzonServiceImpl implements ArzonService {
    @Autowired
    ArzonDao arzonDao;

    @Override
    public void saveArzon(Arzon arzon) {
        arzonDao.saveArzon(arzon);
        if (arzon.getImages() != null && arzon.getImages().size() > 0) {
            arzonDao.saveArzonImages(arzon.getId(), arzon.getImages());
        }
        if (arzon.getActresses() != null && arzon.getActresses().size() > 0) {
            List<Actress> actresses = arzon.getActresses();
            List<Integer> uids = new ArrayList<Integer>();
            for (Actress actress : actresses) {
                Actress actressDB = arzonDao.getByName(actress.getName());
                if (actressDB == null) {
                    arzonDao.saveArzonUU(actress);
                } else {
                    actress = actressDB;
                }
                uids.add(actress.getId());
            }
            arzonDao.saveArzonName(arzon.getId(), uids);
        }
    }
}
